using Game.Main.Model;
using UnityEngine;

namespace Game.Component
{
	public class HairDryerItem : BaseItem
	{
		private Collider2D targetObject;

		private BaseItem targetItem;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
		}

		protected override void LateUpdate()
		{
			base.LateUpdate();
			if (!isDrag)
			{
				return;
			}
			RaycastHit2D[] array = Physics2D.BoxCastAll(base.transform.position + new Vector3(-1.6f, 0.96f), new Vector2(3f, 0.5f), 0f, Vector2.zero, 15f, 4096);
			if (array.Length > 1)
			{
				for (int i = 0; i < array.Length - 1; i++)
				{
					for (int num = array.Length - 1; num > i; num--)
					{
						if (array[num - 1].collider.transform.position.z > array[num].collider.transform.position.z)
						{
							RaycastHit2D raycastHit2D = array[num];
							array[num] = array[num - 1];
							array[num - 1] = raycastHit2D;
						}
					}
				}
			}
			bool flag = false;
			for (int j = 0; j < array.Length; j++)
			{
				RaycastHit2D raycastHit2D2 = array[j];
				if (!(raycastHit2D2.collider != null) || !raycastHit2D2.collider.transform.name.Equals("Head"))
				{
					continue;
				}
				ItemComponentTrigger component = raycastHit2D2.collider.GetComponent<ItemComponentTrigger>();
				if (component.type != ItemComponentTrigger.Type.Head || component.owner.itemData.scriptType != 1)
				{
					continue;
				}
				if (targetObject == null || targetObject != raycastHit2D2.collider)
				{
					if (targetItem != null)
					{
						((CharacterItem)targetItem).StopBlowHairAnim();
					}
					targetObject = raycastHit2D2.collider;
					targetItem = component.owner;
					((CharacterItem)targetItem).PlayBlowHairAnim();
				}
				flag = true;
				break;
			}
			if (targetObject != null && !flag)
			{
				if (targetItem != null)
				{
					((CharacterItem)targetItem).StopBlowHairAnim();
				}
				targetObject = null;
				targetItem = null;
			}
		}

		public override void TouchUp(TouchEventData touchEventData)
		{
			if (targetItem != null)
			{
				((CharacterItem)targetItem).StopBlowHairAnim();
			}
			targetObject = null;
			targetItem = null;
			base.TouchUp(touchEventData);
		}
	}
}
